package com.chenfan.mcn.clients.privilege;

import com.chenfan.common.vo.Response;
import com.chenfan.mcn.utils.RpcUtil;
import com.chenfan.privilege.api.PrivilegeUserRemoteServer;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lizhejin
 */
@FeignClient(value = "chenfan-cloud-privilege",url = "${feign.privilege:}")
public interface PrivilegeClient extends PrivilegeUserRemoteServer {

    /**
     * 获取指定用户所在部门负责人
     *
     * @param user {@link UserDTO}
     * @return {@link DepartmentHeadVO}
     */
    @PostMapping(value = "/department/getDepartmentHead")
    Response<DepartmentHeadVO> getDepartmentHead(@RequestBody UserDTO user);

    /**
     * 根据部门ids获取部门信息
     *
     * @param ids ids
     * @return {@link SDepartment}
     */
    @PostMapping(value = "/department/getDepartmentByIds")
    Response<Map<Long, SDepartment>> getDepartmentByIds(@RequestBody List<Long> ids);

    /**
     * 获取对应的userId
     *
     * @param userNames 用户名称
     * @return 对照表
     */
    @PostMapping(value = "/users/getUserIdsByName")
    Response<Map<String, SUserVo>> getUserIdsByName(@RequestBody List<String> userNames);

    /**
     * 根据用户id获取所属部门信息
     *
     * @param userIds ids
     * @return List<SUserVo>
     */
    @PostMapping(value = "/users/getDepartmentByUserIds")
    Response<List<SUserVo>> getDepartmentByUserIds(@RequestBody List<Long> userIds);

    /**
     * 获取商务部门信息
     *
     * @return {@link List<SDepartment>}
     */
    @GetMapping(value = "/department/getBusinessDepartment")
    Response<List<SDepartment>> getBusinessDepartment();


    /**
     * 获取用户信息
     *
     * @param userId 用户id
     * @return 用户信息
     */
    @GetMapping(value = "/users/getUserById")
    Response<SUser> getUserById(@RequestParam Long userId);

    /**
     * 获取用户信息
     *
     * @param userIds 用户id集合
     * @return 用户信息集合
     */
    @PostMapping(value = "/users/getUserByIds")
    Response<List<SUser>> getUserByIds(@RequestBody List<Long> userIds);

    /**
     * 根据用户id集合获取部门负责人信息
     * @param userIds
     * @return
     */
    @PostMapping(value = "/department/getDepartmentHeadByUserIds")
    Response<Map<Long, DepartmentVO>> getDepartmentHeadByUserIds(@RequestBody List<Long> userIds);

    /**
     * 部门下的人
     *
     * @param departmentIds
     * @return
     */
    @PostMapping(value = "users/getUserByDepartmentId")
    Response<List<SUser>> getUserByDepartmentId(@RequestBody List<Long> departmentIds);


    /**
     * 根据公司名称筛选银行
     * @param companyNameReq
     * @return
     */
    @PostMapping(value = "company/getByCompanyName")
    Response<List<SCompanyBank>> getByCompanyName(@RequestBody CompanyNameReq companyNameReq);

    /**
     * 根据公司名称精确查询公司信息
     * @param companyNames
     * @return
     */
    @PostMapping(value = "/company/searchByCompanyName")
    Response<List<SCompany>> searchByCompanyName(@RequestBody List<String> companyNames);

    /**
     * 获取上级公司
     * @return
     */
    @GetMapping(value = "/company/getParList")
    Response<List<ScompanyRes>> getParList();

    /**
     * 查询权限Code
     * @param menuPrivilegeCode
     * @return
     */
    @GetMapping(value = "/privilege/getSearchPrivilegeCode")
    Response<String> getSearchPrivilegeCode(@RequestParam("menuPrivilegeCode") String menuPrivilegeCode);

    /**
     * 根据用户名批量查询系统账户信息
     * @param userNameList
     * @return
     */
    default Map<String, SUserVo> getUserMapByName(List<String> userNameList) {
        if(CollectionUtils.isEmpty(userNameList)) {
            return new HashMap<>(0);
        }
        return RpcUtil.getObjException(this.getUserIdsByName(userNameList), "根据用户名批量查询系统账户信息异常！");
    }

    /**
     * 获取全部用户
     *
     * @param
     * @return
     */
    @GetMapping(value = "/users/getUsers")
    Response<List<SUserVo>> getUsers();

    /**
     * 通过部门id集合获取部门下用户ID集合
     * @param departmentIds
     * @return
     */
    @PostMapping(value = "/department/getUserIdsByDeptIds")
    Response<List<Long>> getUserIdsByDeptIds(@RequestBody List<Long> departmentIds);
}
